<?php
require_once './libraries/utilitres/run.php';

$path = "../ptnhuan-web1/data/films.txt";
$full_path = realpath($path);
$films = mreadFile($path);
$rating = NULL;
$rating1 = NULL;
?>

<form method="POST">
    <input type="text" name="rating"><br>
    <input type="text" name="rating1"><br>
    <input type="submit" name="submit" value="Search">
</form>

<?php if (isset($_POST['submit'])): ?>
    <?php $rating = (double) $_POST['rating']; ?>
    <?php $rating1 = (double) $_POST['rating1']; ?>
<?php endif; ?>
<?php foreach ($films as $item): ?>
    <?php
    $film = explode(";", $item);
    $img = trim($film[0]);
    ?>
    <?php if (empty($rating) && empty($rating1)): ?>
        <?php if (isset($film[1]) || isset($film[2])): ?>
            <img src = '../ptnhuan-web1/public/images/films/<?php echo $img ?>'> 
            <?php echo $film[1] ?>
            <?php echo $film[2] ?>
            <br>
        <?php endif; ?>
    <?php else: ?>
        <?php if (isset($film[1]) || isset($film[2])): ?>
            <?php if (($rating <= (double) $film[2]) && ($rating1 >= (double) $film[2])): ?>
                <img src = '../ptnhuan-web1/public/images/films/<?php echo $img ?>'> 
                <?php echo $film[1] ?>
                <?php if (!empty($film[2])) echo $film[2] ?>
                <br>
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>
<?php endforeach; ?>

